package com.qianyitian.hope2.analyzer.analyzer;

import com.qianyitian.hope2.analyzer.model.KLineInfo;
import com.qianyitian.hope2.analyzer.model.ResultInfo;
import com.qianyitian.hope2.analyzer.model.Stock;
import com.qianyitian.hope2.analyzer.util.Utils;

import java.util.List;

public class USMACDAnalyzer extends AbstractStockAnalyzer {

    public USMACDAnalyzer() {
    }

    @Override
    public boolean analyze(ResultInfo resultInfo, Stock stock) {
        //当前MACD > 0
        //红柱的个数记录下来
        List<KLineInfo> infos = stock.getkLineInfos();
        if (infos.isEmpty()) {
            return false;
        }

        int currentRedBarNumber = 0;

        KLineInfo today = infos.get(infos.size() - 1);
        double macdToday = today.getMacd();
        if (macdToday < 0) {
            return false;
        }
        int i = infos.size() - 1;
        for (; i >= 0; i--) {
            double macd = infos.get(i).getMacd();
            if (macd < 0) {
                break;
            } else {
                currentRedBarNumber++;
            }
        }
        resultInfo.setValue(currentRedBarNumber+"");
        return true;
    }

    public String format(Stock stock) {
        return "";
    }

    @Override
    public String getDescription() {
        return "MACD 周线红柱";
    }

    public int getWeight() {
        return 50;
    }
}
